from HTMLTags import *

class Report():
	def __init__(self, data):
		self.data = data
		self.destination = "/home/eli/Documents/iv/TestRunner/Reports/"
		self.filename = "output.html"
		self.generateReport()
		
	def generateReport(self):
		report_html = self.generateHtml(self.data)
		self.writeFile(report_html)
		
	def generateHtml(self, data):
		head = HEAD(TITLE('IV Unit Test Report'))
		title = H1('Test Report:')
		table = self.generateTable(data)
		body = BODY(title + table)
		return HTML(head + body)
	
	def generateTable(self, data):
		rows = Sum ([TR(TD(rec.number,Class="Number") + 
				TD(rec.fileName,Class="Filename") +
				TD(rec.category,Class="Category") +
				TD(rec.subcategory,Class="Subcategory") +
				TD(rec.description,Class="Description") + 
				TD(rec.behavior,Class="Behavior") + 
				TD(rec.initial,Class="Initial") +
				TD(rec.passed,Class="Passed") + 
				TD(rec.failed,Class="Failed") +
				TD(rec.reason,Class="Reason")) 
			     for rec in data])

		table = TABLE(TR(TH('Test No.') +
				 TH('File name') +
				 TH('Category') +
				 TH('Subcategory') +
				 TH('Test Description') +
				 TH('Expected Behavior') +
				 TH('Initially') +
				 TH('Passed') +
				 TH('Failed') +
				 TH('Reason for failure')) +
				 rows, Border=1)
		return table
	
	def writeFile(self, html_txt):
		fout = open(self.destination + self.filename, "w")
		fout.write(html_txt.__str__())
		fout.close()

